package com.dog.basics.admin.controller.mtkj;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.mtkj.AdminShopBlEditDto;
import com.dog.basics.bean.dto.admin.mtkj.CheckShopDto;
import com.dog.basics.bean.dto.admin.mtkj.ShopListDto;
import com.dog.basics.bean.vo.admin.mtkj.ShopListVo;
import com.dog.basics.bean.vo.admin.mtkj.ShoppingVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.mtkj.IMtShoppingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * <p>
 * 店铺信息 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@Api(value = "店铺管理模块", tags = "店铺管理模块")
@RestController
@RequestMapping("/admin/shopping")
@AllArgsConstructor
public class MtShoppingController {

    private final IMtShoppingService shoppingService;

    /**
     * 查询商铺
     *      1.根据名称查询商铺
     * @param: page
     * @param: shopListDto
     * @returns
     * @author hangdy
     * @date: 2020/11/12 10:57
     */
    @ApiOperation(value = "查询商铺", notes = "pc:shopping:findShops")
    @GetMapping("/findShops")
    @PreAuthorize("@pms.hasPermission('pc:shopping:findShops')")
    public R<IPage<ShopListVo>> findShops(PageParam page, ShopListDto shopListDto){
        //传入false,null是为了查询所有店铺店铺
        return R.ok(shoppingService.findShopByAdmin(page,shopListDto));
    }

    /**
     * 店铺详细信息
     * @param shopId
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "店铺详细信息", notes = "pc:shopping:shopdetail")
    @ApiImplicitParam(value = "商铺Id", name = "shopId", dataType = "Long", required = true)
    @GetMapping("/webFindById/{shopId}")
    @PreAuthorize("@pms.hasPermission('pc:shopping:shopdetail')")
    public R<ShoppingVo> findById(@Valid @PathVariable Long shopId){
        return R.ok(shoppingService.adminShippingById(shopId));
    }

    /**
     * 删除店铺信息
     * @param id
     * @return
     * @author hangdy
     */
    @SysLog("删除店铺信息")
    @ApiOperation(value = "删除店铺信息", notes = "pc:shopping:shopedelete")
    @ApiImplicitParam(value = "店铺信息Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("@pms.hasPermission('pc:shopping:shopedelete')")
    public R<Boolean> delete(@Valid @PathVariable("id") Long id) {
        return R.ok(shoppingService.adminDeleteShop(id));
    }

    /**
     * 审核店铺操作
     * @param: checkShopDto
     * @returns
     * @author hangdy
     * @date: 2020/11/12 18:34
     */
    @SysLog("审核店铺")
    @ApiOperation(value = "审核店铺", notes = "pc:shopping:checkshope")
    @PutMapping("/checkShop")
    @PreAuthorize("@pms.hasPermission('pc:shopping:checkshope')")
    public R<Boolean> checkShop(CheckShopDto checkShopDto){
        return R.ok(shoppingService.checkShop(checkShopDto.getShopId(),checkShopDto.getCheckStatus()));
    }
    /**
     * 修改店铺分润比例
     * @param: checkShopDto
     * @returns
     * @author hangdy
     * @date: 2020/11/12 18:34
     */
    @SysLog("修改店铺分润比例")
    @ApiOperation(value = "修改店铺分润比例", notes = "pc:shopping:edit")
    @PutMapping("/edit")
    @PreAuthorize("@pms.hasPermission('pc:shopping:edit')")
    public R<Boolean> edit(@Valid @RequestBody AdminShopBlEditDto obj){
        return R.ok(shoppingService.editObj(obj));
    }
}
